package com.gemme.gemme.wode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.adapter.DataBean;
import com.gemme.gemme.adapter.ImageAdapter;
import com.gemme.gemme.adapter.StrGuigeAdapter;
import com.gemme.gemme.gwc.GwcBean;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.view.GuigeDialog;
import com.gemme.gemme.view.StaggeredDividerItemDecoration;
import com.hyphenate.easeui.widget.EaseConversationList;
import com.jaeger.library.StatusBarUtil;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.indicator.RectangleIndicator;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//侧滑删除地址
public class ProductActivity extends AppCompatActivity {
    private static final String TAG = "TestHuanxingActivity";
    protected EaseConversationList conversationListView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product);
        initTop();
        initIntent();
        initView();
//        initBanner();
        initData();
    }
    long id;
    private void initIntent() {
        try {
            Intent intent = getIntent();

            id = intent.getLongExtra("id",-1);
        }catch (Exception e){

        }
    }


    private void initBanner() {
//        DataBean.getTestData()
        ArrayList<DataBean> dataBeans = new ArrayList<>();



        for (int i = 0; i < picList.size(); i++) {
            DataBean dataBean = new DataBean();
            dataBean.setImageRes(picList.get(i));
            dataBeans.add(dataBean);
        }
        Banner banner =  findViewById(R.id.banner);
        banner.addBannerLifecycleObserver(this)//添加生命周期观察者
                .setAdapter(new ImageAdapter(dataBeans))
//                .setIndicator(new CircleIndicator(this))
                .setIndicator(new RectangleIndicator(this))
//                .start()
                .stop()
        ;
    }

    private void initView() {


        findViewById(R.id.guige).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GuigeDialog guigeDialog = new GuigeDialog();
                guigeDialog.showDialog(ProductActivity.this,"");
            }
        });
    }



    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
//        StatusBarUtil.setTransparent(this);
        setAndroidNativeLightStatusBar(this,false);
        StatusBarUtil.setColor(this,getResources().getColor(R.color.product_detail));
       findViewById(R.id.arrow_left).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               finish();
           }
       });
    }

    private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
        View decor = activity.getWindow().getDecorView();
        if (dark) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
    List<String> picList;
    private void initData() {
        if(id <=  -1)
            return;
        String url = DataManager.BaseUrl_weicheng + "mall/shopsku/findSku?id=" + id;
        HashMap<String, String> headHashMap = new HashMap<>();
        headHashMap.put(DataManager.AuthorizationKey,DataManager.getToken(this));
        DataManager.toServer2(this, url, DataManager.GET_TYPE, "", headHashMap, new DataManager.GeResponse(){

            @Override
            public void onResponse(String response) {

                try {
                    System.out.println("");
//                    (new JSONObject((new JSONObject(response)).getString("data")));
                   /* JSONObject jb1 = new JSONObject(response);
                    String data = jb1.getString("data");
                    JSONArray jsonArray = new JSONArray(data);
                    String attributeSpecList = (new JSONObject(jsonArray.getString(0))).getString("attributeSpecList");
                    System.out.println("");*/
                    ProductBean productBean = JSON.parseObject(response, ProductBean.class);

                    picList = productBean.getData().get(0).getShopProductPicturePojo().getPicList();
                    if(picList != null)
                    initBanner();
                    System.out.println("");
                }catch (Exception e){

                }
            }
        });
    }

}




